package com.qidian.tcba.admin.service.impl;

import com.qidian.tcba.admin.model.dto.parkLot.ParkLotManageListDTO;
import com.qidian.tcba.admin.model.dto.parkLotManage.*;
import com.qidian.tcba.admin.model.entity.ParkLot;
import com.qidian.tcba.admin.model.query.NearParkLotQueryDTO;
import com.qidian.tcba.admin.model.query.ParkLotQueryDTO;
import com.qidian.tcba.admin.service.ParkLotService;
import com.qidian.tcba.dao.ParkLotMapper;
import com.qidian.tcba.utils.BeanMapper;
import com.qidian.tcba.utils.LatLonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 停车场信息表 服务实现类
 * </p>
 *
 * @author 冯永龙
 * @since 2021-07-06
 */
@Service
public class ParkLotServiceImpl implements ParkLotService {
    @Autowired
    private ParkLotMapper parkLotMapper;

    @Override
    public List<ParkLotManageListDTO> getParkLotListByName(String name) {
        List<ParkLot> parkLots = parkLotMapper.selectListByName(name);
        return BeanMapper.mapList(parkLots, ParkLotManageListDTO.class);
    }

    @Override
    public List<ParkLotManageListDTO> getParkLotManageList(int orgId) {
        List<ParkLot> parkByOrgId = parkLotMapper.getParkByOrgId(orgId);
        return BeanMapper.mapList(parkByOrgId, ParkLotManageListDTO.class);
    }

    @Override
    public List<ParkLotRecordManageResultDTO> getParkLotManageList(ParkLotManageDTO parkLotManageDTO) {
        List<ParkLot> parkLotManageList = parkLotMapper.getParkLotManageList(parkLotManageDTO);
        return BeanMapper.mapList(parkLotManageList, ParkLotRecordManageResultDTO.class);
    }

    @Override
    public List<ParkLotQueryResultDTO> getParkLotQueryResultList(ParkLotQueryDTO parkLotQueryDTO) {
        List<ParkLot> queryResultParkList = parkLotMapper.getQueryResultParkList(parkLotQueryDTO);
        return BeanMapper.mapList(queryResultParkList, ParkLotQueryResultDTO.class);
    }

    @Override
    public List<ParkLotQueryResultDTO> getNearParkLot(NearParkLotQueryDTO nearParkLotQueryDTO) {
        double[] circleAround = LatLonUtil.getCircleAround(
                nearParkLotQueryDTO.getEntranceLongitude(),
                nearParkLotQueryDTO.getEntranceLatitude(),
                nearParkLotQueryDTO.getQueryRadius());
        nearParkLotQueryDTO.setMinLat(circleAround[0]);
        nearParkLotQueryDTO.setMinLng(circleAround[1]);
        nearParkLotQueryDTO.setMaxLat(circleAround[2]);
        nearParkLotQueryDTO.setMaxLng(circleAround[3]);
        List<ParkLot> nearParkLot = parkLotMapper.getNearParkLot(nearParkLotQueryDTO);
        return BeanMapper.mapList(nearParkLot, ParkLotQueryResultDTO.class);
    }
}
